package chaoyue.study.controller;

import chaoyue.study.bean.Depart;
import chaoyue.study.service.DepartService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("depart")
@RestController
public class DepartController {
    @Resource
    private DepartService departService;

    @PostMapping("save")
    public void saveHandle(@RequestBody Depart depart) {
        departService.saveDepart(depart);
    }

    @DeleteMapping("del/{id}")
    public void deleteHandle(@PathVariable("id") Integer id) {
        departService.removeDepart(id);
    }

    @PutMapping("update")
    public void updateHandle(@RequestBody Depart depart) {
        departService.modifyDepart(depart);
    }

    @GetMapping("get/{id}")
    public Depart getHandle(@PathVariable("id") Integer id) {
        return departService.getDepartById(id);
    }

    @GetMapping("list")
    public List<Depart> listHandle() {
        return departService.listAllDeparts();
    }
}
